"""生成一些图示，打草稿"""
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint, quad

import system as sys

# Mance论文中的示例参数
L = 4.2e-3
C0 = 1.15e-12
Cp = 300.15e-12
Ceq = 2*(C0 + Cp)
Q = 200
r = 2*np.pi*1e5*L/Q
m_Z_BR = sys.System([L, r], [L*Ceq, r*Ceq, 1])
Rf = 1e7
Cf = 3.3e-12
Z_f = sys.System([Rf], [Rf*Cf, 1])
# tao = 
# A0 = 
# A = sys.System([A0], [1, tao])

# 我取的示例参数
L = 5e-3
Cp = 252.15e-12
Ceq = 2*(C0 + Cp)
Q = 100
r = 2*np.pi*1e5*L/Q
my_Z_BR = sys.System([L, r], [L*Ceq, r*Ceq, 1])
tao1,tao2 = 2*np.pi*70, 2*np.pi*350

# #---------------------TIA前放的噪声---------------------------------------
# frequency = np.arange(8e4, 1.3e5, 50)
# my_Z_BR_fc = my_Z_BR.frequency_charac(frequency)
# Z_f_fc = Z_f.frequency_charac(frequency)
# plt.figure(num=1, figsize=(7.5/2.54, 5.5/2.54), dpi=141.2)
# 
# # 热噪声
# thermal_noise_BR = 0.1287*((my_Z_BR_fc.real)**0.5)*1e-9# 桥路热电阻V/Hz^0.5
# thermal_noise_gain_fc = -2*Z_f_fc/my_Z_BR_fc
# th_BR_Uo = thermal_noise_BR * np.abs(thermal_noise_gain_fc)
# plt.semilogy(frequency, th_BR_Uo, label='$e_{BR}$')
# 
# # 等效输入电压噪声
# e_n = 20e-9# 20nV/Hz^{1/2}
# noise_gain_fc = 1 - thermal_noise_gain_fc
# en_Uo = 2**0.5 * e_n * np.abs(noise_gain_fc)
# plt.semilogy(frequency, en_Uo, label='$e_{en}$')
# 
# # 等效输入电流噪声
# i_n = 40e-15
# e_in_Uo = 2**0.5*np.abs(Z_f_fc)*i_n
# plt.semilogy(frequency, e_in_Uo, label='$e_{in}$')
# 
# # 反馈阻抗热噪声
# th_Zf_Uo = 2**0.5*0.1287*((Z_f_fc.real)**0.5)*1e-9
# plt.semilogy(frequency, th_Zf_Uo, label='$e_{zf}$')
# 
# # 总噪声
# total_noise = (th_BR_Uo**2 + en_Uo**2 + e_in_Uo**2 + th_Zf_Uo**2)**0.5
# plt.semilogy(frequency, total_noise, label='total')
# 
# plt.xlabel('frequency/Hz', fontsize=10)
# plt.ylabel(r'Noise PSD/$\mathrm{V/Hz^{1/2}}$', fontsize=10)
# plt.legend(fontsize=8)
# plt.grid()
# # plt.show()


# ------------并联补偿电容阵列对桥路热噪声的影响-------------------
def RC_series(r, C, freq):
    """RC串联的电导"""
    s = 2*np.pi*freq*1j
    return C*s/(1+r*C*s)
rc_a = RC_series(0.5, 1.15e-12, 1e5)
rc_pri = RC_series(0.5, 252.15e-12, 1e5)
rc_1 = RC_series(2e8, 1e-12, 1e5)
rc_2 = RC_series(2e8, 2e-12, 1e5)
rc_3 = RC_series(2e8, 4e-12, 1e5)
rc_Z0 = 1/(rc_a + rc_pri)
print(rc_Z0.real)# 0.099
print(rc_Z0.imag)# -6283.2587
rc_Z = 1/(rc_1 + rc_2 + rc_3 + rc_a + rc_pri)
print(rc_Z.real)# 1.088
print(rc_Z.imag)# -6283.2559
